/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mobiwebinc.compconn.communication;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *this seems to be working 
 * @author suraj
 */
public class Listener {

    ServerSocket socket;

    public Listener(int port) throws IOException {
        socket = new ServerSocket(port);
    }

    public IOHandler getClient() {
        Socket client = null;
        try {
            client = socket.accept();
        } catch (IOException ex) {
            Logger.getLogger(Listener.class.getName()).log(Level.SEVERE, null, ex);
        }
        if(client == null)
            return null;
        IOHandler clientIO = new IOHandler(client);
        return clientIO;
    }

    public void stop() {
        try {
            socket.close();
        } catch (IOException ex) {
            Logger.getLogger(Listener.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
